package com.finer.service.impl;

import com.finer.entity.finance.FinerDamageDatail;
import com.finer.dao.FinerDamageDatailDao;
import com.finer.service.FinerDamageDatailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 损耗记录详情表(FinerDamageDatail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:37
 */
@Service("finerDamageDatailService")
public class FinerDamageDatailServiceImpl implements FinerDamageDatailService {
    @Resource
    private FinerDamageDatailDao finerDamageDatailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerDamageDatail queryById(Integer Id) {
        return this.finerDamageDatailDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerDamageDatail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerDamageDatail> queryByPage(FinerDamageDatail finerDamageDatail, PageRequest pageRequest) {
        long total = this.finerDamageDatailDao.count(finerDamageDatail);
        return new PageImpl<>(this.finerDamageDatailDao.queryAllByLimit(finerDamageDatail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerDamageDatail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerDamageDatail insert(FinerDamageDatail finerDamageDatail) {
        this.finerDamageDatailDao.insert(finerDamageDatail);
        return finerDamageDatail;
    }

    /**
     * 修改数据
     *
     * @param finerDamageDatail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerDamageDatail update(FinerDamageDatail finerDamageDatail) {
        this.finerDamageDatailDao.update(finerDamageDatail);
        return this.queryById(finerDamageDatail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerDamageDatailDao.deleteById(Id) > 0;
    }
}
